package cn.bqjr.eily.web.exception;

import cn.bqjr.eily.web.exception.exclass.BaseException;

import java.util.Date;

public class ErrorInfo {
    private Integer httpStatus;
    private String errorCode;
    private String errorMsg;
    private Date timestamp;
    private Throwable Exception;
    private String requestURL;
    private String requestId;

    public ErrorInfo() {
    }

    public ErrorInfo(BaseException e) {
        ExceptionMapping mapping = e.getExceptionMapping();
        setHttpStatus(mapping.getHttpStatus().value());
        setErrorCode(mapping.getErrorCode());
        setErrorMsg(e.getMessage());
    }

    public Integer getHttpStatus() {
        return httpStatus;
    }

    public void setHttpStatus(Integer httpStatus) {
        this.httpStatus = httpStatus;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public Date getTimestamp() {
        if (null != timestamp) {
            return (Date) timestamp.clone();
        }
        return null;
    }

    public void setTimestamp(Date timestamp) {
        if (timestamp != null) {
            this.timestamp = (Date) timestamp.clone();
        }
    }

    public String getRequestURL() {
        return requestURL;
    }

    public void setRequestURL(String requestURL) {
        this.requestURL = requestURL;
    }

    public Throwable getException() {
        return Exception;
    }

    public void setException(Throwable exception) {
        Exception = exception;
    }

    public String getRequestId() {
        return requestId;
    }

    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }
}
